package com.example.week_12;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by wkzlike on 2022/5/19.
 */

public class DBUti {
    private static String user = "root";
    private static String password = "mypassword";

    private static Connection getConn(String dbName) {
        Connection connection = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://192.168.0.101:3306/" + dbName;
            connection = DriverManager.getConnection(url, user, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return connection;
    }

    public static ResultSet queryReader(String reader_num) {
        ResultSet rs = null;
        Connection connection = getConn("library");
        if (connection != null) {
            try {
                PreparedStatement ps;
                Statement smt = connection.createStatement();
                String sql = "select*fromreaderswherereader_numberLIKE'%" + reader_num + "%'";
                rs = smt.executeQuery(sql);
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        return rs;
    }
}
